<?php
//by willson 105328468@qq.com 2014/10/11
//index page interface
namespace app\admin\controller;

use app\common;
use think\Controller;
use think\Session;
use think\Request;
use think\File;
use think\Paginator;
class Record extends common
{
    //列表
    public function index()
    {
        $where = '';
        $keyword = (isset($_GET['keyword']) && trim($_GET['keyword'])) ? trim($_GET['keyword']) : '';
        $id = (isset($_GET['id'])) ? trim($_GET['id']) : '';
        //搜索条件

        if (strlen($id)) {
            $where = "id='{$id}'";
        }
        //搜索条件
        if ($keyword){
            $where = "title LIKE '%{$keyword}%' OR writer LIKE '%{$keyword}%' OR content LIKE '%{$keyword}%'";
        }

        //查询总数据
        $maxpages = Db('record')->where($where)->count('*');
        //最大页数
        $maxpage = $maxpages / 10;
        // 查询状态为0的数据 并且每页显示10条数据 总记录数为1000
        $list = db('record')->where($where)->paginate(20, $maxpages);
//        return $this->sucReturn($list);exit;
        // 获取分页显示
        $page = $list->render();
//        var_dump($page);exit;
        // 模板变量赋值
        $this->assign("id",$id);
        $this->assign("keyword",$keyword);
        $this->assign('list', $list);
        $this->assign('loginname', $this->login());
        $this->assign('page', $page);
        $this->assign('maxpage', $maxpage);
        $this->assign('maxpages', $maxpages);
        $this->assign('empty', '<span class="empty">没有数据</span>');

        // 渲染模板输出
        return $this->fetch('record/index');
    }

}